package com.qf.controller;

import com.qf.entity.Comment;
import com.qf.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//评论 控制器层
@RestController
@RequestMapping("/CommentController")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 通过商家的id去查询评论表
     * @return
     */
    @RequestMapping("/selCommnetByMid/{m_id}")
    public List<Comment> selCommnetByMid(@PathVariable("m_id") Integer m_id){
        System.out.println("AAAAAAAAAAAAAAA=======SSSSSSSSSS==================="+m_id);
        List<Comment> commentsList = commentService.selCommnetByMid(m_id);
        return commentsList;
    }

    /**
     * 查询商家评分的平均分
     * @param m_id
     * @return
     */
    @RequestMapping("/selAllYes/{m_id}")
    public String selAllYes(@PathVariable("m_id") Integer m_id){
        List<Comment> comments = commentService.selCommnetByMid(m_id);
        double pj = 0.0;
        double num = 0.0;
        int size = comments.size();
        for (Comment c:comments) {
            double e_type = c.getE_type();
            num+=e_type;
        }
        pj = num/size;
        String s = String.valueOf(pj);
        return s;
    }
}
